package com.leaf.lowcode.controller;

import com.alibaba.fastjson.JSONObject;
import com.leaf.lowcode.entity.Fire.Data;
import com.leaf.lowcode.entity.Fire.FireCotrolWater;
import com.leaf.lowcode.entity.smr3001.Fire;
import com.leaf.lowcode.utils.R;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class MeterApi {
    @Autowired
    private RabbitTemplate rabbitTemplate;


    /**
     * 三相电表
     * @param treeMeter
     * @return
     */
    @RequestMapping(value="/tpson/open/device/log/smr3250",method = RequestMethod.POST)
        public R smr3250(@RequestBody JSONObject treeMeter)
    {
      //  System.out.println("进入"+System.currentTimeMillis()+treeMeter);
        String dataType = (String) treeMeter.get("dataType");
        System.out.println("进入三相电表接口");
      //  if(dataType.equals("REAL_DATA_1")||dataType.equals("REAL_DATA_2"))
        if(dataType.equals("REAL_DATA_1"))
        {
              rabbitTemplate.convertAndSend("treeMeter_queue",treeMeter);

        }
        if(treeMeter!=null)
        {
            return R.error(200,"获取数据");
        }
        return R.error(500,"未取数据");
    }
//    public R smr1210(@RequestBody TreeMeter treeMeter)
//    {
//        System.out.println("进入"+System.currentTimeMillis());
//        System.out.println("treeMeter"+treeMeter.getDeviceCode());
//        rabbitTemplate.convertAndSend("treeMeter_queue",treeMeter);
//        if(treeMeter==null)
//        {
//            return R.error(500,"未取数据");
//        }
//        return R.error(500,"未取数据");
//    }


    /**
     * 消防用水
     * @param fireCotrolWater
     * @return
     */

  @RequestMapping(value="/tpson/open/device/log/smr1210/v22",method = RequestMethod.POST)
    public R smr1210(@RequestBody JSONObject fireCotrolWater)
    {
     //   System.out.println("fireCotrolWater"+fireCotrolWater);

        rabbitTemplate.convertAndSend("SMR1210_V2_queuetest",fireCotrolWater);
        if(fireCotrolWater!=null)
        {return R.error(200,"获取数据");}
        return R.error(400,"异常");

    }


    /**
     * 烟感设备
     * @param fire
     * @return
     */
  // @RequestMapping(value="/tpson/open/device/log/smr3001",method = RequestMethod.POST)
    public R smr3001Api(@RequestBody JSONObject fire)
    {
        rabbitTemplate.convertAndSend("smr3001_queue",fire);
        if(fire!=null)
        {return R.ok();}
        return R.error(500,"未取数据");
    }
}
